package web;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyAsyncServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final AsyncContext asyncContext = req.getAsyncContext();
        asyncContext.start(new Runnable() {
            public void run() {
                //业务处理
                asyncContext.complete();
                try {
                    asyncContext.getResponse().getWriter().write("xxxx");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
